package name.fowler.refactoring.simplestore;

import java.util.ArrayList;
import java.util.List;

public class Customer {
	private String name;
	private List<Rental> rentals = new ArrayList<Rental>();

	public Customer(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void addRental(Rental arg) {
		rentals.add(arg);
	}

	public String calculateStatement()
	{
		double totalAmount = 0;
		int renterPoints = 0;
			
		StringBuilder result = new StringBuilder();
		result.append("Rental record for ").append(name).append("\n");
		
		for(Rental each: rentals) {
			double thisAmount = 0;
			
			totalAmount += (thisAmount = each.getAmount());
			renterPoints += each.getRentedPoints();

			// Show figures for this rental
			result.append("\t").append(each.getMovie().getTitle())
				.append("\t").append(thisAmount).append("\n");
		}

		// Add footer lines
		result.append("Amount owed is ").append(totalAmount).append("\n");
		result.append("You earned ").append(renterPoints).append(" frequent renter points.");
		return result.toString();
	}
}

